   function GetRequestFromUrl() {
       //alert('start')
      var url = location.search; //获取url中"?"符后的字串
       //alert(url)
      var theRequest = new Object();
      if (url.indexOf("?") != -1) {
         var str = url.substr(1);
         strs = str.split("&");
         for(var i = 0; i < strs.length; i ++) {
            // alert(strs[i].split("=")[0])
            theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
         }
      }
      /*if isEmptyObject(theRequest){
         theRequest['stime'] = null;
         thRequest['etime'] = null;
      }*/
      return theRequest;
   };


    function getCookie(name) {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(
                        cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    };

function putToView(ldata) {
      var dataNode = document.getElementById("rawdata");
      var childs = dataNode.childNodes;
    if (childs.length==0 && ldata.length==0) {

        document.getElementById("rawcount").value=0
    } else{
        document.getElementById("rawcount").value=childs.length + ldata.length

    }
      /*for(var i = 0; i < childs.length; i++) {
          dataNode.removeChild(childs[i]);
      }*/
      for (var i=0;i<ldata.length;i++){
          data = ldata[i]
          
         $( "#rawdata" ).prepend( "<p>"+data+"</p>");
         }
   };


function refresh(){ 
  var csrftoken = getCookie('csrftoken');
  request = GetRequestFromUrl();
  request['csrfmiddlewaretoken'] = csrftoken
  
  $.ajax({
      type: "POST",
      url: ".",

      data: request,
      dataType: "json",
      success: function(data) {
        //alert(data.writeCount[0]),

        putToView(data.datas)
        setTimeout(
                       refresh,     
                       5000
                   );
      },
    });
}


   function waitForMsg(){
      

      $.getJSON("/msg/", request, 
             function(data){  
               putToView(data)
               setTimeout(
                       refresh,     
                       1000
                   );
         });
   };